<template>
  <div>
    <div class="app">
      <div class="head">
        <p>{{searchId}}</p>
        <span class="arrow" @click="Jump_path"></span>
      </div>
    </div>
    <div class="nav">
       <div class="jtspan">
          <span :class="['iconfont',{'ys':index==1}] " id="jtspan-1" @click="setindex(1)">&#xe62d;</span>
          <span :class="['iconfont',{'ys':index==2}] " id="jtspan-2" @click="setindex(2)">&#xe62e;</span>
        </div>
      <van-tabs v-model="active" animated @click="onClick">
        <van-tab v-for="item in navlist" :title="item.name" :key="item.link">
        </van-tab>
      </van-tabs>
    </div>
    <div class="Navigation">
      <ul>
        <li v-for="item in navlistdata" :key="item.id" @click="Jump_alis(item.id)">
          <div><img :src="item.cover" alt="" /></div>
          <div class="text1">{{ item.name }}</div>
          <div class="text2">{{ item.sales }}人想买</div>
          <div class="text3">
            <span class="span1">￥{{ item.coupon_price }}</span>
            <span class="span2">￥{{ item.price }}</span>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { getSearchClassic } from "../api/home.js";
export default {
  props: ["link1",'aidname'],
  data() {
    return {
      active: 0,
      navlistdata: null,
      sort: null,
      index:0,//价格排序切换
      navlist: [
        {
          name: "推荐",
          link: 323,
          sort: null,
        },
        {
          name: "上新",
          link: 324,
          sort: "new",
        },
        {
          name: "销量",
          link: 326,
          sort: "hot",
        },
        {
          name: "价格",
          link: 325,
          sort: "price_asc",
          // sort:"price_desc"
        },
      ],
      searchId:null,
    };
  },
  methods: {
    Jump_path() {
      this.$router.go(-1);
    },
    //跳转到商品详情页
    Jump_alis(id){
// console.log(id);
      this.$emit('getalisid',id)
      this.$router.push({name:'alis'})
       
    } ,
    //商品列表
    getnavlist() {
      getSearchClassic({search:this.searchId,sort:this.sort}).then(
        (data) => {
          this.navlistdata = data.data;
          // console.log(this.navlistdata);
          console.log(data.data);
        }
      );
    },
    //切换
    onClick(name, title) {
      console.log(name, title);
      this.navlist.forEach((item) => {
        if(title=='价格'){
            this.index=1
          }else{
            this.index=0
          }
        if (title == item.name) {
          
          this.sort = item.sort;
        }
      });
    },
    //切换价格箭头
    setindex(index){
      if(this.index==0){
        return
      }
this.index=index
if(this.index==1){
this.sort ="price_asc"
}else{
this.sort ="price_desc"
}
    }
  },
  created() {
    // console.log(this.link1);
    this.searchId = this.$route.query.id
    this.getnavlist();
  },
  watch: {
    sort(){
      this.getnavlist();
    },
  },
};
</script>
<style scoped>
.head {
  position: fixed;
  top: 0;
  left: 0%;
  width: 100%;
  height: 50px;
  text-align: center;
  line-height: 50px;
  border-bottom: 1px solid #ccc;
  color: rgb(59, 59, 59);
  z-index: 999;
  background: #fff;
}
.head p {
    font-weight: bold;
}
.arrow {
  display: block;
  width: 12px;
  height: 23px;
  position: absolute;
  top: 15px;
  left: 20px;
  z-index: 999;
  background: url(../../public/assets/images/ic_arrow_home.png);
  transform: rotate(180deg);
}
.nav {
  position: relative;
  margin-top: 50px;
  width: 100%;
  height: 50px;

}
.nav >>> .van-tabs__line {
  background-color: rgb(27, 36, 45);
  height: 2px;
  width: 25%;
}
.nav >>> .van-tabs--line .van-tabs__wrap {
  height: 50px;
}
.Navigation {
  margin-top: 10px;
  position: relative;
  border-radius: 10px;
  overflow: hidden;
}
.Navigation ul {
  width: 100%;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 60px;
}
.Navigation ul li {
  width: 49%;
  height: 280px;
  margin-bottom: 5px;
  background: #fff;
}
.Navigation ul li img {
  width: 100%;
  height: 174px;
  border-radius: 10px;
  overflow: hidden;
}
.text1 {
  line-height: 23px;
  padding: 0 10px;
  color: black;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 5px;
}
.text2 {
  color: rgb(159, 159, 159);
  font-size: 12px;
  padding: 0 10px;
  margin-bottom: 10px;
}
.text3 {
  padding: 0 10px;
  margin-bottom: 5px;
}
.span1 {
  font-size: 18px;
  color: rgb(236, 69, 9);
  font-weight: 500;
}
.span2 {
  font-size: 12px;
  color: rgb(159, 159, 159);
  text-decoration: line-through;
}
.iconfont {
  color: #ccc;
  font: 13px;
}
.ys {
  color: black;
}
.jtspan{
  position: absolute;
  top: 9px;
  right: 8px;
  z-index: 999;
}
.jtspan span{
display: block;
}
</style>